package com.baosight.sczx.zm.service;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.IndexConfiger;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.common.zm.cInterface.cs.WorkSchedule;
import com.baosight.sczx.zm.domain.ZM95;

/**
 * 首页安全模版-三违
 * <p>Title: ServiceZM94.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 郭淑芳
 * @version 1.0
 * <pre>Histroy:
 *          2012-11-7 上午05:33:57  郭淑芳  Create
 *</pre>
 */
public class ServiceZM95 extends ServiceEPBase {
	
	/**
	 * 初始化
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZM95</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-11-8上午02:33:13 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) 
	{
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		outInfo.addBlock(WorkSchedule.getWorkScheduleBlock("cmes.cl.workNum", false));//三违班次
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cl.sourceClassify"));//三违来源
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cl.classify"));//三违分类
		return outInfo;
	}
	
	/**
	 * 三违查询
	 * <p>Function: TernateQuery</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2012-11-7上午05:35:54 郭淑芳
	 * </p>
	 *
	 */
	public EiInfo query(EiInfo inInfo) {

		EiInfo inInfo1 = new EiInfo();
		EiInfo inInfo2 = new EiInfo();
		String isMore = "yes"; // 判断前台显示更多按钮或者处理按钮

		if ("否".equals(IndexConfiger.getInstance().getIsLeader())) {
			String department = UserSession.getInSessionProperty("orgCode") == null ? "" : UserSession.getInSessionProperty("orgCode").toString();

//			Object ext2 = Department.getInstance().getDepartmentMapById(department).get("ext2");
//			if(ext2 !=null)
//			{
//				if ("采煤".equals(ext2.toString()) || "掘进".equals(ext2.toString())) {
					StaticTools.setQueryParameters(inInfo1, "fdManageDepartmentId", department, true);
					StaticTools.setQueryParameters(inInfo2, "fdResponseDepartmentId", department, true);
					isMore = "no";
//				}
//			}
		}
		StaticTools.setQueryParameters(inInfo1, "fdUserId", UserSession.getLoginName(), true);
		StaticTools.setQueryParameters(inInfo2, "fdUserId", UserSession.getLoginName(), true);

		StaticTools.setQueryParameters(inInfo1, "fdStatus", "未处理", true);
		StaticTools.setQueryParameters(inInfo2, "fdStatus", "未反馈", true);

		// 只显示前十条数据
		StaticTools.setQueryParameters(inInfo1, "rownum", "10", true);
		StaticTools.setQueryParameters(inInfo2, "rownum", "10", true);

		inInfo1 = super.query(inInfo1, "ZM95.query", new ZM95());
		inInfo2 = super.query(inInfo2, "ZM95.query", new ZM95());

		EiBlock eiBlock1 = new EiBlock("untreatedResult");
		EiBlock eiBlock2 = new EiBlock("noFeedback");
		ZM95 zm95 = new ZM95();
		eiBlock1.setBlockMeta(zm95.eiMetadata);
		eiBlock2.setBlockMeta(zm95.eiMetadata);
		inInfo.addBlock(eiBlock1);
		inInfo.addBlock(eiBlock2);
		inInfo.getBlock("untreatedResult").addRows(inInfo1.getBlock("result").getRows());
		inInfo.getBlock("noFeedback").addRows(inInfo2.getBlock("result").getRows());

		inInfo.set("num1", inInfo1.getBlock("result").getRowCount());
		inInfo.set("num2", inInfo2.getBlock("result").getRowCount());
		inInfo.set("isMore", isMore);
		//inInfo.addBlock(RoadWay.getAllRoadWay("cmes.cl.roadWay", true));//所在巷道

		return inInfo;
	}
}
